package com.dsit.sq;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.dsit.sq.mydefineview.LongColorfulProgressBar;
import com.dsit.sq.mydefineview.PullToRefreshBase;
import com.dsit.sq.mydefineview.PullToRefreshScrollView;

import org.json.JSONArray;
import org.json.JSONObject;

import java.sql.Date;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;

/**
 * 其他参数界面
 * Created by dsit_dev04 on 2016/10/9.
 */
public class OtherActivity extends BaseActivity implements OnClickListener {
    private ImageView otherReurnImageView;
    private TextView otherDataTextView;
    private TextView otherStatusTextView;
    private TextView pcuDataTextView;
    private TextView pcuStatusTextView;
    private TextView powerInputTempDataTextView;
    private TextView powerInputTempStatusTextView;
    private TextView conditionerPowerDataTextView;
    private TextView conditionerPowerStatusTextView;
    private TextView conditionerPressureDataTextView;
    private TextView conditionerPressureStatusTextView;
    private TextView mainTempDataTextView;
    private TextView mainTempStatusTextView;
    private TextView deputyTempDataTextView;
    private TextView deputyTempStatusTextView;
    private TextView conditionerWinSpeedDataTextView;
    private TextView conditionerWinSpeedStatusTextView;
    private TextView fuelInputTempDataTextView;
    private TextView fuelInputTempStatusTextView;
    private TextView fuelOutputTempDataTextView;
    private TextView fuelOutputTempStatusTextView;
    private TextView powerBatteryTempDataTextView;
    private TextView powerBatteryTempStatusTextView;
    private TextView dcfTempDataTextView;
    private TextView dcfTempStatusTextView;
    private TextView fcsBaseDataTextView;
    private TextView fcsBaseStatusTextView;
    private TextView fcsExternalDataTextView;
    private TextView fcsExternalStatusTextView;

    private ImageView openHotManagerImageView;
    private LinearLayout hotManagerLinear;
    private ImageView openExperimentManagerImageView;
    private LinearLayout experimentLinear;
    private ImageView openFcsImageView;
    private LinearLayout fcsLinear;

    private LongColorfulProgressBar pcuTempProgressBar;
    private LongColorfulProgressBar inputWaterProgressBar;
    private LongColorfulProgressBar conditionerPowerProgressBar;
    private LongColorfulProgressBar containerPressureProgressBar;
    private LongColorfulProgressBar mainTempProgressBar;
    private LongColorfulProgressBar deputyTempProgressBar;
    private LongColorfulProgressBar settingWindSpeedProgressBar;
    private LongColorfulProgressBar fuelBatteryOutputTempProgressBar;
    private LongColorfulProgressBar powerBatteryTempProgressBar;
    private LongColorfulProgressBar dcfTempProgressBar;
    private ImageView fcsBasicImageView;
    private ImageView fcsExtenalImageView;

    private final int other_dianjipower = 8;
    private final int pcu_tempreture = 9;
    private final int power_battery_input_temp = 10;
    private final int conditioner_power = 11;
    private final int getConditioner_pressure = 12;
    private final int main_temp = 13;
    private final int deputy_temp = 14;
    private final int conditioner_set_windspeed = 15;
    private final int fuel_input_temp = 16;
    private final int fuel_output_temp = 17;
    private final int power_battery_temp = 18;
    private final int dcf_temp = 19;
    private final int fcs_base_status = 20;
    private final int fcs_extenal_status = 21;

    private PullToRefreshScrollView pullOtherScrollView;
    private LinearLayout otherLinearLayout;
    private ScrollView otherScrollView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_other);
        otherReurnImageView = (ImageView) findViewById(R.id.other_return_button);
        otherReurnImageView.setOnClickListener(this);

        ProtoMsgDispatcher.getInstance().addDataListener(dataListener);

        LayoutInflater inflater = LayoutInflater.from(getApplication());
        otherLinearLayout =(LinearLayout) inflater.inflate(R.layout.other_layout,null);

        otherDataTextView = (TextView) otherLinearLayout.findViewById(R.id.dianji_data_text);
        otherStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.dianji_status_text);
        openHotManagerImageView = (ImageView) otherLinearLayout.findViewById(R.id.open_hot_manager_view);
        openHotManagerImageView.setOnClickListener(this);
        hotManagerLinear = (LinearLayout) otherLinearLayout.findViewById(R.id.hot_manager_linear);
        openExperimentManagerImageView = (ImageView) otherLinearLayout.findViewById(R.id.open_experiment_view);
        openExperimentManagerImageView.setOnClickListener(this);
        experimentLinear = (LinearLayout) otherLinearLayout.findViewById(R.id.experiment_linear);
        openFcsImageView = (ImageView) otherLinearLayout.findViewById(R.id.open_fcs_view);
        openFcsImageView.setOnClickListener(this);
        fcsLinear = (LinearLayout) otherLinearLayout.findViewById(R.id.fcs_linear);

        pcuDataTextView = (TextView) otherLinearLayout.findViewById(R.id.pcu_data_text);
        pcuStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.pcu_status_text);
        powerInputTempDataTextView = (TextView) otherLinearLayout.findViewById(R.id.inputwater_data_text);
        powerInputTempStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.inputwater_status_text);
        conditionerPowerDataTextView = (TextView) otherLinearLayout.findViewById(R.id.contionerpower_data_text);
        conditionerPowerStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.contionerpower_status_text);
        conditionerPressureDataTextView = (TextView) otherLinearLayout.findViewById(R.id.pressure_data_text);
        conditionerPressureStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.pressure_status_text);
        mainTempDataTextView = (TextView) otherLinearLayout.findViewById(R.id.maintemp_data_text);
        mainTempStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.maintemp_status_text);
        deputyTempDataTextView = (TextView) otherLinearLayout.findViewById(R.id.deputytemp_data_text);
        deputyTempStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.deputytemp_status_text);
        conditionerWinSpeedDataTextView = (TextView) otherLinearLayout.findViewById(R.id.windspeed_data_text);
        conditionerWinSpeedStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.windspeed_status_text);
        fuelInputTempDataTextView = (TextView) otherLinearLayout.findViewById(R.id.fuelbattery_data_text);
        fuelInputTempStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.fuelbattery_status_text);
        fuelOutputTempDataTextView = (TextView) otherLinearLayout.findViewById(R.id.powerbattery_data_text);
        fuelOutputTempStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.powerbattery_status_text);
        powerBatteryTempDataTextView = (TextView) otherLinearLayout.findViewById(R.id.powerbattery_one_data_text);
        powerBatteryTempStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.powerbattery_one_status_text);
        dcfTempDataTextView = (TextView) otherLinearLayout.findViewById(R.id.dcftemp_data_text);
        dcfTempStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.dcftemp_status_text);
        fcsBaseDataTextView = (TextView) otherLinearLayout.findViewById(R.id.fcsbasic_data_text);
        fcsBaseStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.fcsbasic_status_text);
        fcsExternalDataTextView = (TextView) otherLinearLayout.findViewById(R.id.fcsexternal_data_text);
        fcsExternalStatusTextView = (TextView) otherLinearLayout.findViewById(R.id.fcsexternal_status_text);

        pcuTempProgressBar = (LongColorfulProgressBar) otherLinearLayout.findViewById(R.id.pcu_temp_image);
        inputWaterProgressBar = (LongColorfulProgressBar) otherLinearLayout.findViewById(R.id.inputwater_image);
        conditionerPowerProgressBar = (LongColorfulProgressBar) otherLinearLayout.findViewById(R.id.contioner_power_image);
        containerPressureProgressBar = (LongColorfulProgressBar) otherLinearLayout.findViewById(R.id.contioner_pressure_image);
        mainTempProgressBar = (LongColorfulProgressBar) otherLinearLayout.findViewById(R.id.main_temp_image);
        deputyTempProgressBar = (LongColorfulProgressBar)otherLinearLayout.findViewById(R.id.deputy_temp_image);
        settingWindSpeedProgressBar = (LongColorfulProgressBar) otherLinearLayout.findViewById(R.id.wind_speed_image);
        settingWindSpeedProgressBar.totalRetangleCounts = 16;
        fuelBatteryOutputTempProgressBar = (LongColorfulProgressBar) otherLinearLayout.findViewById(R.id.power_battery_output_image);
        powerBatteryTempProgressBar = (LongColorfulProgressBar) otherLinearLayout.findViewById(R.id.power_battery_temp_one_image);
        dcfTempProgressBar = (LongColorfulProgressBar) otherLinearLayout.findViewById(R.id.deftemp_image);
        fcsBasicImageView = (ImageView) otherLinearLayout.findViewById(R.id.fcs_basic_image);
        fcsExtenalImageView = (ImageView) otherLinearLayout.findViewById(R.id.fcs_external_image);

        pullOtherScrollView = (PullToRefreshScrollView)findViewById(R.id.other_pullscroll);
        pullOtherScrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ScrollView>() {

            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                new GetDataTask().execute();
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {

            }
        });
        otherScrollView = pullOtherScrollView.getRefreshableView();
        otherScrollView.setVerticalScrollBarEnabled(false);
        otherScrollView.addView(otherLinearLayout);
//        powerBatteryScrollView.addView(createTextView());
        setLastUpdateTime();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ProtoMsgDispatcher.getInstance().removeDataListener(dataListener);
    }

    private class GetDataTask extends AsyncTask<Void, Void, String[]> {

        @Override
        protected String[] doInBackground(Void... params) {
            // Simulates a background job.
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
            }
            return null;
        }

        @Override
        protected void onPostExecute(String[] result) {
            pullOtherScrollView.onPullDownRefreshComplete();
            setLastUpdateTime();
            super.onPostExecute(result);
        }
    }
    private void setLastUpdateTime() {
        String text = formatDateTime(System.currentTimeMillis());
        pullOtherScrollView.setLastUpdatedLabel(text);
    }

    private SimpleDateFormat mDateFormat = new SimpleDateFormat("HH:mm:ss");
    private String formatDateTime(long time) {
        if (0 == time) {
            return "";
        }

        return mDateFormat.format(new Date(time));
    }
    private boolean hotIsInvisible = true;
    private boolean exIsInvisible = true;
    private boolean fcsIsInvisible = true;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.other_return_button:
                finish();
                break;
            case R.id.open_hot_manager_view:
                hotIsInvisible = !hotIsInvisible;
                if (hotIsInvisible) {
                    hotManagerLinear.setVisibility(View.GONE);
                    openHotManagerImageView.setBackgroundResource(R.mipmap.icon_down);
                } else {
                    hotManagerLinear.setVisibility(View.VISIBLE);
                    openHotManagerImageView.setBackgroundResource(R.mipmap.icon_up);
                }
                break;
            case R.id.open_experiment_view:
                exIsInvisible = !exIsInvisible;
                if (exIsInvisible) {
                    experimentLinear.setVisibility(View.GONE);
                    openExperimentManagerImageView.setBackgroundResource(R.mipmap.icon_down);
                } else {
                    experimentLinear.setVisibility(View.VISIBLE);
                    openExperimentManagerImageView.setBackgroundResource(R.mipmap.icon_up);
                }
                break;
            case R.id.open_fcs_view:
                fcsIsInvisible = !fcsIsInvisible;
                if (fcsIsInvisible) {
                    fcsLinear.setVisibility(View.GONE);
                    openFcsImageView.setBackgroundResource(R.mipmap.icon_down);
                } else {
                    fcsLinear.setVisibility(View.VISIBLE);
                    openFcsImageView.setBackgroundResource(R.mipmap.icon_up);
                }
                break;
            default:
                break;
        }
    }

    private DataListener dataListener = new DataListener() {
        @Override
        public void onUpdateData(ProtoMessage msg) {
            if(msg.getActionId().equals("canbus.msg")){
                byte[] data = msg.getContentData();
                Log.i("main_activity", "收到回调");
                String str = new String(data, 0, data.length);
                try {
                    JSONArray array = new JSONArray(str);
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject object = (JSONObject) array.get(i);
                        int id = object.getInt("id");
                        Double value = object.getDouble("value");
                        Bundle bundle = new Bundle();
                        Message message = new Message();
                        message.setData(bundle);
                        bundle.putDouble("value", value);
                        switch (id) {
                            case other_dianjipower:
                                message.what = other_dianjipower;
                                mHandler.sendMessage(message);
                                break;
                            case pcu_tempreture:
                                message.what = pcu_tempreture;
                                mHandler.sendMessage(message);
                                break;
                            case power_battery_input_temp:
                                message.what = power_battery_input_temp;
                                mHandler.sendMessage(message);
                                break;
                            case conditioner_power:
                                message.what = conditioner_power;
                                mHandler.sendMessage(message);
                                break;
                            case getConditioner_pressure:
                                message.what = getConditioner_pressure;
                                mHandler.sendMessage(message);
                                break;
                            case main_temp:
                                message.what = main_temp;
                                mHandler.sendMessage(message);
                                break;
                            case deputy_temp:
                                message.what = deputy_temp;
                                mHandler.sendMessage(message);
                                break;
                            case conditioner_set_windspeed:
                                message.what = conditioner_set_windspeed;
                                mHandler.sendMessage(message);
                                break;
                            case fuel_input_temp:
                                message.what = fuel_input_temp;
                                mHandler.sendMessage(message);
                                break;
                            case fuel_output_temp:
                                message.what = fuel_output_temp;
                                mHandler.sendMessage(message);
                                break;
                            case power_battery_temp:
                                message.what = power_battery_temp;
                                mHandler.sendMessage(message);
                                break;
                            case dcf_temp:
                                message.what = dcf_temp;
                                mHandler.sendMessage(message);
                                break;
                            case fcs_base_status:
                                message.what = fcs_base_status;
                                mHandler.sendMessage(message);
                                break;
                            case fcs_extenal_status:
                                message.what = fcs_extenal_status;
                                mHandler.sendMessage(message);
                                break;
                            default:
                                break;
                        }
                        Log.i("data", object.toString());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    };

    Handler mHandler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message message) {
            try {
                Bundle bundle = new Bundle();
                bundle = message.getData();
                Double data = bundle.getDouble("value");
                switch (message.what) {
                    case other_dianjipower:
                        otherDataTextView.setText(formatDouble(data) + "kw");
                        otherStatusTextView.setText("");
                        break;
                    case pcu_tempreture:
                        pcuDataTextView.setText(formatDouble(data) + "℃");
                        if ((data - 70.0) > 0.00001) {
                            pcuStatusTextView.setText("过高");
                        } else if ((data - (-20.0)) < 0.00001) {
                            pcuStatusTextView.setText("过低");
                        } else {
                            pcuStatusTextView.setText("正常");
                        }
                        data = 40 + data;
                        int progress = (int) ((float) (data / 160) * 100);
                        pcuTempProgressBar.setProgress(progress);
                        break;
                    case power_battery_input_temp:
                        if (data == 254.0) {
                            powerInputTempDataTextView.setText("Init");
                            powerInputTempStatusTextView.setText("");
                            inputWaterProgressBar.setProgress(0);
                        } else if (data == 255.0) {
                            powerInputTempDataTextView.setText("Error");
                            powerInputTempStatusTextView.setText("");
                            inputWaterProgressBar.isAllRed = true;
                            inputWaterProgressBar.setProgress(100);
                            mHandler.sendEmptyMessage(80);
                        } else {
                            data = data * 0.5 - 40;
                            powerInputTempDataTextView.setText(formatDouble(data) + "℃");
                            if ((data - 30.0) > 0.00001) {
                                powerInputTempStatusTextView.setText("过高");
                            } else {
                                powerInputTempStatusTextView.setText("正常");
                            }
                            data = 40 + data;
                            int progress1 = (int) ((float) (data / 126.5) * 100);
                            inputWaterProgressBar.setProgress(progress1);
                        }
                        break;
                    case conditioner_power:
                        conditionerPowerDataTextView.setText(formatDouble(data) + "KW");
                        conditionerPowerStatusTextView.setText("");
                        int progress2 = (int) ((float) (data / 7.65) * 100);
                        conditionerPowerProgressBar.setProgress(progress2);
                        break;
                    case getConditioner_pressure:
                        conditionerPressureDataTextView.setText(formatDouble(data) + "KPaG");
                        conditionerPressureStatusTextView.setText("");
                        int progress3 = (int) ((float) (data / 3570) * 100);
                        containerPressureProgressBar.setProgress(progress3);
                        break;
                    case main_temp:
                        if (data == 30.0) {
                            mainTempDataTextView.setText("High");
                            mainTempProgressBar.setProgress(100);
                        } else if (data == 0.0) {
                            mainTempDataTextView.setText("Low");
                            mainTempProgressBar.setProgress(0);
                        } else if (data == 31.0) {
                            mainTempDataTextView.setText("Reserved");
                            mainTempProgressBar.setProgress(100);
                        } else if ((data - 1.0) > 0 && (data - 29.0) < 0) {
                            data = data * 0.5 + 15.5;
                            mainTempDataTextView.setText(formatDouble(data) + "℃");
                            int progress4 = (int) ((float) (data / 28) * 100);
                            mainTempProgressBar.setProgress(progress4);
                        }
                        break;
                    case deputy_temp:
                        if (data == 30.0) {
                            deputyTempDataTextView.setText("High");
                            deputyTempProgressBar.setProgress(100);
                        } else if (data == 0.0) {
                            deputyTempDataTextView.setText("Low");
                            deputyTempProgressBar.setProgress(0);
                        } else if (data == 31.0) {
                            deputyTempDataTextView.setText("Reserved");
                            deputyTempProgressBar.setProgress(100);
                        } else if ((data - 1.0) > 0.00001 && (data - 29.0) < 0.00001) {
                            data = data * 0.5 + 15.5;
                            deputyTempDataTextView.setText(formatDouble(data) + "℃");
                            int progress5 = (int) ((float) (data / 28) * 100);
                            deputyTempProgressBar.setProgress(progress5);
                        }
                        deputyTempStatusTextView.setText("");
                        break;
                    case conditioner_set_windspeed:
                        conditionerWinSpeedStatusTextView.setText("");
                        if (data == 0.0) {
                            conditionerWinSpeedDataTextView.setText("OFF");
                            settingWindSpeedProgressBar.setProgress(7);
                        } else if (data == 1.0) {
                            conditionerWinSpeedDataTextView.setText("一档");
                            settingWindSpeedProgressBar.setProgress(14);
                        } else if (data == 2.0) {
                            conditionerWinSpeedDataTextView.setText("二档");
                            settingWindSpeedProgressBar.setProgress(21);
                        } else if (data == 3.0) {
                            conditionerWinSpeedDataTextView.setText("三档");
                            settingWindSpeedProgressBar.setProgress(28);
                        } else if (data == 4.0) {
                            conditionerWinSpeedDataTextView.setText("四档");
                            settingWindSpeedProgressBar.setProgress(35);
                        } else if (data == 5.0) {
                            conditionerWinSpeedDataTextView.setText("五档");
                            settingWindSpeedProgressBar.setProgress(42);
                        } else if (data == 6.0) {
                            conditionerWinSpeedDataTextView.setText("六档");
                            settingWindSpeedProgressBar.setProgress(49);
                        } else if (data == 7.0) {
                            conditionerWinSpeedDataTextView.setText("七档");
                            settingWindSpeedProgressBar.setProgress(53);
                        } else if (data == 8.0) {
                            conditionerWinSpeedDataTextView.setText("八档");
                            settingWindSpeedProgressBar.setProgress(59);
                        } else if (data == 9.0) {
                            conditionerWinSpeedDataTextView.setText("九档");
                            settingWindSpeedProgressBar.setProgress(64);
                        } else if (data == 10.0) {
                            conditionerWinSpeedDataTextView.setText("十档");
                            settingWindSpeedProgressBar.setProgress(70);
                        } else if (data == 11.0) {
                            conditionerWinSpeedDataTextView.setText("十一档");
                            settingWindSpeedProgressBar.setProgress(75);
                        } else if (data == 12.0) {
                            conditionerWinSpeedDataTextView.setText("十二档");
                            settingWindSpeedProgressBar.setProgress(83);
                        } else if (data == 13.0) {
                            conditionerWinSpeedDataTextView.setText("十三档");
                            settingWindSpeedProgressBar.setProgress(90);
                        } else if (data == 14.0) {
                            conditionerWinSpeedDataTextView.setText("十四档");
                            settingWindSpeedProgressBar.setProgress(95);
                        } else if (data == 15.0) {
                            conditionerWinSpeedDataTextView.setText("AUTO档");
                            settingWindSpeedProgressBar.setProgress(100);
                        }
                        break;
                    case fuel_input_temp:
                        fuelInputTempDataTextView.setText(formatDouble(data) + "℃");
                        fuelInputTempStatusTextView.setText("");
                        break;
                    case fuel_output_temp:
                        fuelOutputTempDataTextView.setText(formatDouble(data) + "℃");
                        if ((data - 78.0) > 0.00001) {
                            fuelOutputTempStatusTextView.setText("过高");
                        } else {
                            fuelOutputTempStatusTextView.setText("正常");
                        }
                        data = 40 + data;
                        int progress6 = (int) ((float) (data / 204.6) * 100);
                        fuelBatteryOutputTempProgressBar.setProgress(progress6);
                        break;
                    case power_battery_temp:
                        if (data == 254.0) {
                            powerBatteryTempDataTextView.setText("Init");
                            powerBatteryTempStatusTextView.setText("");
                            powerBatteryTempProgressBar.setProgress(0);
                        } else if (data == 255.0) {
                            powerBatteryTempDataTextView.setText("Error");
                            powerBatteryTempStatusTextView.setText("");
                            powerBatteryTempProgressBar.isAllRed = true;
                            powerBatteryTempProgressBar.setProgress(100);
                            mHandler.sendEmptyMessage(80);
                        } else {
                            data = data * 0.5 - 40;
                            powerBatteryTempDataTextView.setText(formatDouble(data) + "℃");
                            if ((data - 10.0) < 0) {
                                powerBatteryTempStatusTextView.setText("过低");
                            } else {
                                powerBatteryTempStatusTextView.setText("正常");
                            }
                            data = 40 + data;
                            int progress7 = (int) ((float) (data / 126.5) * 100);
                            powerBatteryTempProgressBar.setProgress(progress7);
                        }
                        break;
                    case dcf_temp:
                        dcfTempDataTextView.setText(formatDouble(data) + "℃");
                        if ((data - 78.0) > 0.00001) {
                            dcfTempStatusTextView.setText("过高");
                        } else {
                            dcfTempStatusTextView.setText("正常");
                        }
                        data = 40 + data;
                        int progress8 = (int) ((float) (data / 180) * 100);
                        dcfTempProgressBar.setProgress(progress8);
                        break;
                    case fcs_base_status:
                        fcsBaseStatusTextView.setText("");
                        if (data == 0.0) {
                            fcsBaseDataTextView.setText("Ready");
                            fcsBasicImageView.setBackgroundResource(R.mipmap.bg_fcs_ready);
                        } else if (data == 2.0) {
                            fcsBaseDataTextView.setText("Enable");
                            fcsBasicImageView.setBackgroundResource(R.mipmap.bg_fcs_enable);
                        } else if (data == 4.0) {
                            fcsBaseDataTextView.setText("PowerUp");
                            fcsBasicImageView.setBackgroundResource(R.mipmap.bg_fcs_powerup);
                        } else if (data == 5.0) {
                            fcsBaseDataTextView.setText("Error");
                            fcsBasicImageView.setBackgroundResource(R.mipmap.bg_fcs_error);
                        }
                        break;
                    case fcs_extenal_status:
                        if (data == 0.0) {
                            fcsExternalDataTextView.setText("Non-output");
                            fcsExtenalImageView.setBackgroundResource(R.mipmap.bg_fcs_no_output);
                        } else if (data == 1.0) {
                            fcsExternalDataTextView.setText("Start Up");
                            fcsExtenalImageView.setBackgroundResource(R.mipmap.bg_fcs_start_up);
                        } else if (data == 2.0) {
                            fcsExternalDataTextView.setText("Shut Off");
                            fcsExtenalImageView.setBackgroundResource(R.mipmap.bg_fcs_shut_off);
                        } else if (data == 3.0) {
                            fcsExternalDataTextView.setText("Idle");
                            fcsExtenalImageView.setBackgroundResource(R.mipmap.bg_fcs_idle);
                        }
                        fcsExternalStatusTextView.setText("");
                        break;
                    case 80:
                        powerBatteryTempProgressBar.isAllRed = false;
                        inputWaterProgressBar.isAllRed = false;
                        break;
                    default:
                        break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    };

    private String formatDouble(Double data) {
        DecimalFormat format = new DecimalFormat("0.00");
        return format.format(data);
    }
}
